package com.snake.springboot.custom.service.assemble.base;


import com.snake.springboot.custom.api.model.base.CustMainAccountModel;
import com.snake.springboot.custom.api.request.base.CustMainAccountReq;
import com.snake.springboot.custom.api.request.base.CustomReq;
import com.snake.springboot.custom.dao.mybatis.entity.base.CustMainAccountDO;
import org.snake.common.code.SerialNumberGeneratorFactory;
import org.snake.common.security.MD5Util;
import org.snake.common.utils.IllegalStrUtils;
import org.snake.common.utils.PropertyUtils;

/**
 * <p>商户主账号组装器
 * 类{@code CustMainAccAssemble} </br>
 * 创建时间2025/2/8 14:38
 * @author yangxt
 * @see
 */
public class CustMainAccAssemble {


    public static CustMainAccountDO mainAccDOAss(CustMainAccountModel model) {
        CustMainAccountDO accountDO =new CustMainAccountDO();
        PropertyUtils.copyProperties(accountDO,model);
        return accountDO;
    }

    public static CustMainAccountDO mainAccDOAss(CustomReq customReq) {
        CustMainAccountReq account = customReq.getMainAccount();
        IllegalStrUtils.checkPwd(account.getPassword());
        CustMainAccountDO accountDO =new CustMainAccountDO();
        PropertyUtils.copyProperties(accountDO,account);
        accountDO.setMainAccountId(SerialNumberGeneratorFactory.buildId4Bean());
        accountDO.setCustomId(customReq.getCustomId());
        accountDO.setPassword(MD5Util.encrypt(account.getPassword()));
        return accountDO;
    }

    public static CustMainAccountModel mainAccModelAss(CustMainAccountDO accountDO) {
        CustMainAccountModel model =new CustMainAccountModel();
        PropertyUtils.copyProperties(model,accountDO);
        return model;
    }
}
